package cn.iocoder.yudao.module.system.controller.app.wechat_card;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.wechat_card.WeChatCardUtil;
import cn.iocoder.yudao.module.system.wechat_card.dto.create_card.CardDTO;
import cn.iocoder.yudao.module.system.wechat_card.dto.general_card.GeneralCardUseDTO;
import cn.iocoder.yudao.module.system.wechat_card.dto.giftcard.GiftCardPageDTO;
import cn.iocoder.yudao.module.system.wechat_card.dto.giftcard.UpdateGiftCardPageDTO;
import cn.iocoder.yudao.module.system.wechat_card.dto.order.BatchGetOrderDTO;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "微信礼品卡")
@RestController
@RequestMapping("/system/wechat_card")
public class WeChatCardController {

    @Resource
    private WeChatCardUtil weChatCardUtil;

    @GetMapping("/getAccessToken")
    @Operation(summary = "获取access_token 小程序")
    public CommonResult<String> getAccessToken() {
        return success(weChatCardUtil.getAccessToken());
    }

    @GetMapping("/getAccessTokenWeChat")
    @Operation(summary = "获取access_token 公众号")
    public CommonResult<String> getAccessTokenWeChat() {
        return success(weChatCardUtil.getAccessTokenWeChat());
    }

    @PostMapping("/uploadImg")
    @Operation(summary = "上传卡券图片素材 (上传的图片限制文件大小限制1MB，仅支持JPG、PNG格式。)")
    public CommonResult<String> uploadImg(@RequestParam("file") MultipartFile file) {
        return success(weChatCardUtil.uploadImg(file));
    }

    @PostMapping("/createCard")
    @Operation(summary = "创建礼品卡")
    public CommonResult<String> createCard(@RequestBody CardDTO cardDTO) {
        return success(weChatCardUtil.createCard(cardDTO));
    }

    @PostMapping("/addGiftCard")
    @Operation(summary = "创建-礼品卡货架")
    public CommonResult<String> addGiftCard(@RequestBody GiftCardPageDTO giftCardPageDTO) {
        return success(weChatCardUtil.addGiftCard(giftCardPageDTO));
    }

    @GetMapping("/getGiftCard")
    @Operation(summary = "查询-礼品卡货架信息")
    public CommonResult<JSONObject> getGiftCard(@RequestParam("page_id") String pageId) {
        return success(weChatCardUtil.getGiftCard(pageId));
    }

    @PostMapping("/updateGiftCard")
    @Operation(summary = "修改-礼品卡货架")
    public CommonResult<String> updateGiftCard(@RequestBody UpdateGiftCardPageDTO updateGiftCardPageDTO) {
        return success(weChatCardUtil.updateGiftCard(updateGiftCardPageDTO));
    }

    @GetMapping("/batchGetGiftCard")
    @Operation(summary = "查询-礼品卡货架列表")
    public CommonResult<JSONArray> batchGetGiftCard() {
        return success(weChatCardUtil.batchGetGiftCard());
    }

    @GetMapping("/maintainGiftCard")
    @Operation(summary = "下架-礼品卡货架")
    public CommonResult<JSONObject> maintainGiftCard(@RequestParam("page_id") String pageId) {
        return success(weChatCardUtil.maintainGiftCard(pageId));
    }

    @GetMapping("/getOrder")
    @Operation(summary = "礼品卡订单-查询-单个礼品卡订单信息")
    public CommonResult<JSONObject> getOrder(@RequestParam("order_id") String order_id) {
        return success(weChatCardUtil.getOrder(order_id));
    }

    @GetMapping("/batchGetOrder")
    @Operation(summary = "礼品卡订单-查询-批量查询礼品卡订单信息")
    public CommonResult<JSONObject> batchGetOrder(@RequestBody BatchGetOrderDTO batchGetOrderDTO) {
        return success(weChatCardUtil.batchGetOrder(batchGetOrderDTO));
    }

    @PostMapping("/generalCardUpdateUser")
    @Operation(summary = "更新用户礼品卡信息接口")
    public CommonResult<JSONObject> generalCardUpdateUser(@RequestBody GeneralCardUseDTO generalCardUseDTO) {
        return success(weChatCardUtil.generalCardUpdateUser(generalCardUseDTO));
    }

    @PostMapping("/consumeCard")
    @Operation(summary = "核销用户礼品卡接口")
    public CommonResult<String> consumeCard(@RequestParam("code") String code, @RequestParam("card_id") String card_id) {
        return success(weChatCardUtil.consumeCard(code, card_id));
    }

    @PostMapping("/cardGet")
    @Operation(summary = "查询礼品卡信息接口")
    public CommonResult<JSONObject> cardGet(@RequestParam("code") String code, @RequestParam("card_id") String card_id) {
        return success(weChatCardUtil.cardGet(code, card_id));
    }


}
